namespace G1.EngineV
{

    using System;
    using System.Collections.Generic;
    using Android.Graphics;

    public class AssetManager
    {

        private List<Asset> _AssetList;

        public AssetManager()
        {
            this._AssetList = new List<Asset>();
        }

        public void Add( Asset Asset )
        {

            foreach ( Asset _Asset in this._AssetList )
                if ( _Asset.Name.Equals( Asset.Name ) )
                    throw new Exception( "Asset already exists" );

            this._AssetList.Add( Asset );
        }

        public void Remove( Asset Asset )
        {
            this._AssetList.Remove( Asset );
        }

        public void Remove( String Name )
        {

            int AssetIndex = -1;

            if ( ( AssetIndex = this._GetAssetIndexByName( Name ) ) > -1 )
                this._AssetList.RemoveAt( AssetIndex );
            else throw new Exception( "Asset does not exist" );

        }

        private int _GetAssetIndexByName( String Name )
        {

            for ( int i = 0; i < this._AssetList.Count; i++ )
            {
                if ( this._AssetList[i].Name.Equals( Name ) )
                    return i;
            }

            return -1;
        }

        public Asset Get( String Name )
        {

            int AssetIndex = -1;

            if ( ( AssetIndex = this._GetAssetIndexByName( Name ) ) > -1 )
                return this._AssetList[AssetIndex];

            return null;
        }


    }
}